import requests
import json

# 后端API基本URL
BASE_URL = "http://localhost:8000"

# 管理员登录信息
ADMIN_CREDENTIALS = {
    "username": "admin",
    "password": "123456"
}

def simple_login_test():
    """简单测试登录接口，捕获详细错误信息"""
    print("开始简单登录测试...")
    
    # 登录请求
    login_url = f"{BASE_URL}/auth/login"
    try:
        response = requests.post(
            login_url,
            data=ADMIN_CREDENTIALS,
            headers={"Content-Type": "application/x-www-form-urlencoded"}
        )
        
        print(f"状态码: {response.status_code}")
        print(f"响应头: {response.headers}")
        print(f"响应内容: {response.text}")
        
        # 尝试解析JSON响应
        try:
            response_json = response.json()
            print(f"解析后的JSON响应: {json.dumps(response_json, ensure_ascii=False, indent=2)}")
        except json.JSONDecodeError:
            print("响应内容不是有效的JSON格式")
    except Exception as e:
        print(f"请求发生异常: {str(e)}")

if __name__ == "__main__":
    simple_login_test()